home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
overwrt.exe
/
OVRTPU.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-10-12
|
2KB
|
93 lines
Unit OvrTpu;
INTERFACE
uses
WObjects, WinTypes, WinProcs;
const
wm_ChangeCaret = wm_User + 1000;
type
POverwrite = ^TOverwrite;
TOverwrite = object(TEdit)
Overwrite : boolean;
constructor InitResource(AParent : PWindowsObject;
ResourceID, ATextLen : word);
procedure WMGetDlgCode(var Msg : TMessage);
virtual wm_First + wm_GetDlgCode;
procedure ENSetFocus(var Msg : TMessage);
virtual nf_first + en_SetFocus;
procedure WMChangeCaret(var Msg : TMessage);
virtual wm_First + wm_ChangeCaret;
procedure WMKeyDown(var Msg : TMessage);
virtual wm_First + wm_KeyDown;
procedure Edit(var Msg : TMessage);
virtual wm_first + wm_Char;
end;
IMPLEMENTATION
constructor TOverwrite.InitResource(AParent : PWindowsObject;
ResourceID, ATextLen : Word);
begin
TEdit.InitResource(AParent, ResourceID, ATextLen);
Overwrite:=false;
end;
procedure TOverwrite.WMGetDlgCode(var Msg : TMessage);
begin
Msg.Result:=Dlgc_WantAllKeys;
end;
procedure TOverwrite.ENSetFocus(var Msg : TMessage);
begin
HideCaret(LoWord(Msg.lParam));
SendMessage(HWindow,wm_ChangeCaret,0,0);
end;
procedure TOverwrite.WMChangeCaret(var Msg : TMessage);
var
Dc : HDc;
Tm : TTextMetric;
CyHeight,
CxWidth : integer;
begin
DC:=GetDC(HWindow);
GetTextMetrics(DC,Tm);
cyHeight:=Tm.TmHeight;
cxWidth:=Tm.TmAveCharWidth;
ReleaseDC(HWindow,DC);
DestroyCaret;
if (NOT Overwrite) then
CreateCaret(HWindow,0,2,cyHeight)
else
CreateCaret(HWindow,0,cxWidth,cyHeight);
ShowCaret(HWindow);
end;
procedure TOverwrite.WMKeyDown(var Msg : TMessage);
begin
if (Msg.wParam = VK_INSERT) then
begin
Overwrite:=(NOT Overwrite);
SendMessage(HWindow,wm_ChangeCaret,0,0);
end
else
DefWndProc(Msg);
end;
procedure TOverwrite.Edit(var Msg : TMessage);
var
lPos : longint;
begin
if (Overwrite) AND (NOT (Msg.wParam IN [VK_DELETE,VK_BACK,VK_ESCAPE])) then
begin
lPos:=SendMessage(HWindow,Em_GetSel,0,0);
SendMessage(HWindow,Em_SetSel,0,MakeLong(LoWord(lPos),LoWord(lPos)+1));
SendMessage(HWindow,Em_ReplaceSel,0,Longint(nil));
end;
DefWndProc(Msg);
end;
end.